﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoUpdate.Common
{
    public  class BusinessProcess
    {
        /// <summary>
        /// 关闭相关进程
        /// </summary>
        /// <param name="processName"></param>
        public static void CloseProcess(string processName)
        {
            try
            {
                processName = processName.Replace(".exe", ""); //去掉.exe后缀因为p.ProcessName获取的名称是不带后缀的
                Process[] processArray = Process.GetProcesses();
                foreach (var p in processArray)
                {
                    if (p.ProcessName == processName)
                    {
                        p.Kill();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 启动进程
        /// </summary>
        /// <param name="fileName"></param>
        public static void StartProcess(string fileName)
        {
            try
            {
                ProcessStartInfo info = new ProcessStartInfo();
                info.FileName = fileName;
                info.Arguments = "";
                info.UseShellExecute = false;
                info.WorkingDirectory = Global.LocalFolder;
                Process.Start(info);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}
